(function() {
    var key = common.getQueryString("key");
    var id = common.getQueryString("id");
    var houseNo=common.getQueryString("houseNo");
    var houseId=common.getQueryString("houseId");
    var devId=common.getQueryString("devId");
    var selfFileFolder=common.getQueryString("fileFolder");
    //售房表Id
    var sId=common.getQueryString("sId");
    var configs = {
        agencyCompany:{
            idField: "companyId",
            backUrl: "./agencyManage/companyList.html",
            buttonUrls: [{
                url: "./agencyManage/companyInfo.html",
                text: "中介公司信息"
            }]
        },
        agencyStore:{
            idField: "storeId",
            backUrl: "./agencyManage/storeList.html",
            buttonUrls: [{
                url: "./agencyManage/storeInfo.html",
                text: "中介公司信息"
            }]
        },
        goldenAgentInfo:{
            idField: "agentId",
            backUrl: "./agentManage/goldenList.html",
            buttonUrls: [{
                url: "./agentManage/agentInfo.html",
                text: "经纪人信息"
            }]
        },
        blackAgentInfo:{
            idField: "agentId",
            backUrl: "./agentManage/blackList.html",
            buttonUrls: [{
                url: "./agentManage/agentInfo.html",
                text: "经纪人信息"
            }]
        },
        agentHouse:{
            idField: "houseId",
            backUrl: "./agentHouse/agentHouseList.html",
            buttonUrls: [{
                url: "./agentHouse/agentHouseInfo.html",
                text: "房源信息"
            }]
        },
        esheyiHouse:{
            idField: "houseId",
            backUrl: "./rewardHouse/esheyiHouseList.html",
            buttonUrls: [
                {
                    url: "./rewardHouse/esheyiHouseInfo.html",
                    text: "房源信息"
                },
                {
                    url: "./rewardHouse/houseAudioList.html",
                    text: "音频信息"
                }
            ]
        },
        rewardHouse:{
            idField: "rewardId",
            backUrl: "./rewardHouse/rewardHouseList.html",
            buttonUrls: [
                {
                    url: "./rewardHouse/esheyiHouseInfo.html",
                    text: "房源信息"
                },
                {
                    url: "./rewardHouse/rewardInfo.html",
                    text: "悬赏信息"
                },
                {
                    url: "./rewardHouse/houseSingleRecordList.html",
                    text: "查看记录"
                }
            ]
        },
        lockRecord:{
            idField: "lockId",
            backUrl: "./lockManage/lockedList.html",
            buttonUrls: [{
                url: "./lockManage/lockRecordList.html",
                text: "开锁记录"
            }]
        },
        agentCredit:{
            idField: "agentId",
            backUrl: "./creditManage/agentCreditList.html",
            buttonUrls: [{
                url: "./creditManage/agentCreditRecordList.html",
                text: "经纪人信息"
            }]
        }
};

    createButtonListPage(key, id);

    function createButtonListPage(key, id) {
        var $backButton = $("<div>").addClass("form-group").append($("<button>").addClass("btn btn-w-m btn-white goBack").text("返回"));
        var config = configs[key];
        config.buttonUrls.forEach(function(url, index) {
            var buttonColorClass = "btn-white";
            if (index === 0) {
                var firstUrl=url.url + '?' + config.idField + '=' + id+'&houseNo='+houseNo+'&houseId='+houseId+'&devId='+devId;
                $(".J_iframe").attr('src', firstUrl);
                buttonColorClass = "btn-success";
            }
            $("#buttons").append($("<div>").addClass("form-group").append($("<button>").addClass("btn btn-w-m").addClass(buttonColorClass).attr("data-url", url.url).text(url.text)));
        });
        $("#buttons").append($backButton);
        $("button").on("click", function(ev) {
            if ($(this).hasClass("goBack")) {
                //TODO wanglei check this code or support sub-submenu
                var backUrl=config.backUrl;
                if(key==="companyContactList"){
                    backUrl+="?agencyId="+common.getQueryString("agencyId")
                }
                window.location.href = backUrl;
            }
            var url = $(this).data('url');
            if (!!url === false) return;
            url+="?" + config.idField + "=" + id+'&houseNo='+houseNo+'&fileFolder='+selfFileFolder+'&houseId='+houseId+'&devId='+devId;
            if(key==="sale" || key==="personalSaleList"|| key==="saleControl"){
                //售房子菜单包括多个id逻辑,sId和houseId混用
                url+="&sId="+sId;
            }
            $("iframe").attr('src', url);
            $("button.btn-success").addClass('btn-white').removeClass('btn-success');
            $(this).addClass('btn-success').removeClass('btn-white');
            ev.stopPropagation();
        });
    }
}).call(this);
